package com.xiaoqi.api.service.Impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaoqi.api.constant.StatusConst;
import com.xiaoqi.api.dto.SchoolCenterDTO;
import com.xiaoqi.api.mapper.SchoolCenterMapper;
import com.xiaoqi.api.query.SchoolCenterQuery;
import com.xiaoqi.api.service.SchoolCenterService;
import com.xiaoqi.api.vo.SchoolCenterVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.neu.api.utils.PageResult;
import com.neu.api.pojo.SchoolCenter;

import javax.annotation.Resource;
import java.util.List;

@Service
@Component
public class SchoolCenterServiceImpl implements SchoolCenterService {

    @Resource
    private SchoolCenterMapper schoolCenterMapper;

    @Override
    public PageResult<SchoolCenterVO> find(SchoolCenterQuery schoolCenterQuery) {

        //设置是否需要分页
        PageHelper.startPage(schoolCenterQuery.getPage(),schoolCenterQuery.getPageSize());  //告诉PageHelper此处需要分页

        //List
        Page<SchoolCenterVO> page = (Page<SchoolCenterVO>) schoolCenterMapper.find(schoolCenterQuery);

        PageInfo<SchoolCenterVO> pageInfo = page.toPageInfo();


        List<SchoolCenterVO> schoolCenterVOList = pageInfo.getList();
        long total = pageInfo.getTotal();


        PageResult<SchoolCenterVO> pageResult = new PageResult<>();
        pageResult.setTotal(total);
        pageResult.setList(schoolCenterVOList);

        return pageResult;
    }




    @Override
    public void add(SchoolCenterDTO schoolCenterDTO) {
        SchoolCenter schoolCenter = new SchoolCenter();  //name loginName phone
        BeanUtils.copyProperties(schoolCenterDTO,schoolCenter);


        schoolCenter.setStatus(StatusConst.ACTIVE_STATUS);

        schoolCenterMapper.add(schoolCenter);
    }




}
